package com.pxene.dmp.aspect;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import com.pxene.dmp.constant.BaseConstant;

@Aspect
@Component
public class TaskLogAspect {
	
	private Log log = LogFactory.getLog(TaskLogAspect.class);
	
	@Pointcut("execution(* org.springframework.batch.core.step.tasklet.Tasklet.execute(..))")
	public void taskExecute() {
	}
	
	@Before("taskExecute()")
	public void logTaskBegin(JoinPoint point) {
		log.info(BaseConstant.LOG_PREFIX + point.getThis() + " begin");
	}
	
	@AfterReturning("taskExecute()")
	public void logTaskEnd(JoinPoint point) {
		log.info(BaseConstant.LOG_PREFIX + point.getThis() + " end");
	}
	
	@AfterThrowing("taskExecute()")
	public void logTaskException(JoinPoint point) {
		log.info(BaseConstant.LOG_PREFIX + point.getThis() + " exception");
	}
	
}
